﻿/*
* 公共的动画脚本
*/
/* ========================================================================
    首页轮播(普通轮播)
  ========================================================================*/
(function(){
	function RuleCarousel(element,options){
		this.element=$(element);
	       this.options = $.extend({}, RuleCarousel.defaults ,options);
		this.list=this.element.find('a');
		this.num=this.element.find('li');
		this.timer=null;
		this.ri=0;
	}
	RuleCarousel.defaults={
		time:5000,
		autoPlay:true 
  	}
  	RuleCarousel.prototype.Play=function(index){
  		this.list.eq(index).fadeIn().siblings().fadeOut();
		this.num.removeClass('cur').eq(index).addClass('cur');
  	}
	RuleCarousel.prototype.autoPlay=function(){
		var that=this;
		this.timer=setInterval(function(){
			that.ri++;
			if(that.ri>that.num.length-1){
				that.ri=0;
			}
			that.Play(that.ri);
		},that.options.time)
	}
	RuleCarousel.prototype.hevent=function(){
		var that=this;
		this.num.hover(function(){
			clearInterval(that.timer);
			that.ri=$(this).index();
			that.Play(that.ri);
		},function(){
			that.autoPlay();
		})
	}
	RuleCarousel.prototype.handle=function(){
		if(this.options.autoPlay){
			this.autoPlay();
		}
		this.hevent();
	}
	/*===插件定义===*/
	function Plugin(options) {//插件定义缓存
	      return this.each(function () {
	          var $this=$(this);
	          var data=$this.data('RuleCarousel');
	          var option= $.extend({}, typeof options == 'object' && options);
	          if(!data){
	              $this.data('RuleCarousel', (data=new RuleCarousel($this, option)))
	          }
	          data.handle();
	      })
	  }
  
  /*调用*/
  $.fn.RuleCarousel= Plugin;

})(jQuery);

/* ========================================================================
    切换轮播
  ========================================================================*/
(function(){

  	function PrdSwitch(element,options){
  		this.element=element;
	       this.options = $.extend({}, PrdSwitch.defaults ,options);
  	}
  	PrdSwitch.defaults={
		num:3,
		autoPlay:true,
		speed:800
  	}
  	PrdSwitch.prototype.init=function(){
 		this.prd=this.element.find('ul');
	       this.prdlist= this.prd.find('li');
	       this.wl=this.element.find('.s_mask_l');
	       this.wr=this.element.find('.s_mask_r');
     	       this.i=0;
	       this.lwidth=this.prdlist.outerWidth();
	       this.marginw=parseInt(this.prdlist.css('marginRight'));
	       this.integer=Math.ceil(this.prdlist.length/this.options.num);
	       this.mod=this.prdlist.length%this.options.num;
      		this.mwidth=(this.lwidth+this.marginw)*this.options.num;
  	}
  	PrdSwitch.prototype.handle=function(){
  		var _this=this;
  		this.init();
  		this.wl.click(function(){
			_this.i--;
			if(_this.i<0){
				_this.i=_this.integer-1;
			}
			_this.prd.animate({left:'-'+_this.mwidth*_this.i+'px'},_this.options.speed);
  		})
  		this.wr.click(function(){
  			_this.i++;
			if(_this.i>_this.integer-1){
				_this.i=0;
			}
			_this.prd.animate({left:'-'+_this.mwidth*_this.i+'px'},_this.options.speed);
  		})
  	}
  		/*===插件定义===*/
	function Plugin(options) {//插件定义缓存
	      return this.each(function () {
	          var $this=$(this);
	          var data=$this.data('PrdSwitch');
	          var option= $.extend({}, typeof options == 'object' && options);
	          if(!data){
	              $this.data('PrdSwitch', (data=new PrdSwitch($this, option)))
	          }
	          data.handle();
	      })
	  }
  
  	 /*调用*/
  	$.fn.PrdSwitch= Plugin;

})(jQuery);

/* ========================================================================
    品牌服务点击轮播
  ========================================================================*/
  (function(){
	function Lun(element) {
		this.element=$(element);
	}
	Lun.prototype.Varinit=function(){//变量初始
		this.ul_=this.element.find('.showing_pic ul');
		this.pre= this.element.find('.pre');
		this.next= this.element.find('.next');
		this.num_=this.ul_.find('li').length;
		this.ul_.css('width',this.num_*875);
		this.i=0;
	}
	Lun.prototype.click_=function(){
		var that=this;
		that.next.click(function(){
			that.i++;
			if(that.i>that.num_-1){
				that.i=0;
			}
			that.go();
		})
		that.pre.click(function(){
			that.i--;
			if(that.i<0){
				that.i=that.num_-1;
			}
			that.go();
		})
	}

	Lun.prototype.go=function(){
		var that=this;
		that.ul_.stop(true).animate({left:-that.i*875})
	}

	Lun.prototype.show_hide=function(){
		$('.list ul li').mousemove(function(){
			$(this).addClass('act').siblings().removeClass('act');
			$('.showing').hide().eq($(this).index()).show();
		})
	}

	Lun.prototype.moving=function(){
		var that=this;
		setInterval(function(){
			that.next.click();
		},4000)
	}

	Lun.prototype.SiteInit=function(){
		this.Varinit();//定义变量
		this.click_();//点击函数
		this.show_hide();//移动有列表显示隐藏
		this.moving();//自动播放
	}

	/*===插件定义===*/
	function Plugin(options) {//插件定义缓存
		return this.each(function () {
			var $this=$(this);
			var data=$this.data('Lun');
			if(!data){
				$this.data('Lun', (data=new Lun($this)))
			}
			data.SiteInit();
		})
	}
	/*调用*/
	$.fn.Lun= Plugin;
})(jQuery);